<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UploadController extends Controller
{
    //
    public function index()
    {
    	return view('upload.index');
    }

    public function doUpload(Request $request)
    {
    	if ($request->hasFile('mypic')) {
    		if ($request->file('mypic')->isValid()) {
			    $file = $request->file('mypic');
			    $ext = $file->getClientOriginalExtension();
			    $picname = time().rand(1000,9999).'.'.$ext;
			    $file->move('./uploads/',$picname);
			    if($file->getError()>0){
			    	echo '上传失败';
			    }else{
			    	echo '上传成功';
			    }
			}
		}
        //等比缩放
        $img = Image::make('./uploads/'.$picname);
        $img->resize(100, null, function ($constraint) {
                                    $constraint->aspectRatio();
                                    $constraint->upsize();
                                });
        $img->save('./uploads/s_'.$picname);
    }
}
